package org.one.stone.soup.grfxML.plugin.widget;

import org.one.stone.soup.grfxML.DataNode;
import org.one.stone.soup.grfxML.DataPlugin;
import org.one.stone.soup.grfxML.DataPoint;
import org.one.stone.soup.grfxML.DataString;
import org.one.stone.soup.grfxML.DataTranslation;
import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.CompareException;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public class SuperString extends SimplePlugin {

	private static final int ARG_FROM = 0;
	private static final int ARG_TO = 1;

	DataTranslation from;

	DataString fromName = new DataString();
	String currentFromName;

	DataPoint to = new DataPoint();

/**
 * SuperString constructor comment.
 */
public SuperString(GrfxMLEngine engine) {
	super(engine);
}
/**
 * compare method comment.
 */
public int compare(Field target) throws CompareException {
	return 0;
}
/**
 * getClone method comment.
 */
public DataPlugin getClone() {
	return null;
}
/**
 * getClone method comment.
 */
public DataPlugin getClone(String path) {
	return null;
}
/**
 * getValue method comment.
 */
public String getValue(String name) {
	return null;
}
/**
 * initialize method comment.
 */
public void initialize()
{
	setFrom();
}
/**
 * process method comment.
 */
public void process()
{
 try{

	if(from==null || fromName.hasChanged() || !currentFromName.equals(fromName.getValue()) )
	{
		setFrom();
	}

	if(from!=null)
	{
		DataPoint fromP = from.getPositionView();
		to.setValueX( fromP.getValueX(),this );
		to.setValueY( fromP.getValueY(),this );
	}

 }catch(LockException le){}
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{
	fromName	=	grfxMLCaster.cast(fromName,getArg(fromName,ARG_FROM,store));
	to 			=	grfxMLCaster.cast(to,getArg(to,ARG_TO,store));
}
/**
 * replace method comment.
 */
public void replace(org.one.stone.soup.mjdb.data.field.Field oldObj, org.one.stone.soup.mjdb.data.field.Field newObj)
{
	fromName	=	grfxMLCaster.replace(fromName,oldObj,newObj);
	to			=	grfxMLCaster.replace(to,oldObj,newObj);
}
public void setFrom()
{
	if( getEngine().getAPI().getField( fromName.getValue() ) instanceof DataNode )
	{
		from = ((DataNode)getEngine().getAPI().getField( fromName.getValue() )).getTranslation();
		currentFromName = fromName.getValue();
	}
}
/**
 * stop method comment.
 */
public void stop() {}
}
